<html>
<head>
    <title>我是消息消费者</title>
</head>

<body>
<h1>Jerry</h1>

<h1>对方的视频</h1>
            <hr>
            <div class="video_container" align="center">
                <video id="remote_video" poster="img/video_fill.jpg" controls autoplay></video>
            </div>


    <script src="/socket.io/socket.io.js"></script>
    <!-- <script src="https://webrtc.github.io/adapter/adapter-latest.js"></script> -->
    <script src="./js/adapter-latest.js"></script>
    <script>

var remoteVideo = document.getElementById('remote_video');
        var socket=io();
        socket.emit('assignusername','jerry');
        socket.emit('joinRoom',"room1");

        socket.on('beep',(msg)=>{
            console.log("收到服务端的消息 "+ msg);
        })


        var config = {
    'iceServers': [
        
    // {
    //     'urls': 'stun:stun.l.google.com:19302'
    // }
    {
        "urls": "stun:192.168.1.16:3478"
    },{
        "urls": "stun:192.168.1.16:3478",
        "username":"test",
             "credential":"123456"
    }
]
};

var pc;


socket.on('signal', function (message) {
    pc = new RTCPeerConnection(config);
    pc.setRemoteDescription(new RTCSessionDescription(message));
    pc.createAnswer().then(function (answer) {
        pc.setLocalDescription(answer);
        socket.emit('signal', answer);
    });

    pc.addEventListener('icecandidate', function (event) {
        var iceCandidate = event.candidate;
        if (iceCandidate) {
            socket.emit('ice', iceCandidate);
        }
    });

    pc.addEventListener('addstream', function (event) {
        remoteVideo.srcObject = event.stream;
    });
});

socket.on('ice', function (message) {
    pc.addIceCandidate(new RTCIceCandidate(message));
});

    </script>

</body>


</html>